home *** CD-ROM | disk | FTP | other *** search
- program Zoundz;
- {Program name: Zoundz.Pas }
- {Function: Allows creation of 'snd ' resource ID=9000. }
- {History: 4/17/89 Original by Prototyper. }
- {Modified: 5/1/89 by Kirk Chase}
- uses
- PrintTraps, Message, save_changes, About, Untitled, InitTheMenus, HandleTheMenus, Sound, MyGlobals, MyFileStuff, MyPrintStuff;
-
- const
- WNETrapNum = $60;
- UnImplTrapNum = $9F;
- MultiEvt = 15;
- bit0 = 31;
- GrayRgnLowMemGlobal = $9EE;
-
- var {Main variables}
- myEvent: EventRecord;
- ResumePeek: WindowPeek;
- theWorld: SysEnvRec;
- doneFlag, DoIt, WNE, sysResult: boolean;
- code, theValue: integer;
- whichWindow: WindowPtr;
- dragRect: Rect;
- mResult: longint;
- theMenu, theItem: integer;
- chCode: integer;
- ch: char;
- myPt: Point;
- title: str255;
- nDocs, message, index, sleep: integer;
- theFile: AppFile;
- theErr: OSErr;
-
- procedure InitMac; {initializes Macintosh}
- begin
- MoreMasters; {This reserves space for more handles}
- InitGraf(@thePort); {Quickdraw Init}
- InitFonts; {Font manager init}
- InitWindows; {Window manager init}
- InitMenus; {Menu manager init}
- TEInit; {Text edit init}
- InitDialogs(nil); {Dialog manager}
-
- FlushEvents(everyEvent, 0);{Clear out all events}
- InitCursor; {Make an arrow cursor}
- end;
-
- procedure InitApp; {initialize application}
- var
- tempHandle: handle;
- begin
- doneFlag := FALSE; {Do not exit program yet}
- Init_My_Menus; {Initialize menu bar}
- MyDoc := DocPtr(NewPtr(sizeof(DocRec))); {get doc}
- ThePrintRec := nil; {print initialization}
- PrOpen;
- tempHandle := NewHandle(sizeof(TPrint));
- ThePrintRec := THPrint(tempHandle);
- PrintDefault(ThePrintRec);
- PageRect := ThePrintRec^^.prInfo.rpage;
- PrClose;
-
- dragRect := screenbits.bounds;{Get screen area, l,t,r,b, drag area}
- SetRect(dragRect, dragRect.Left + 10, dragRect.Top + 25, dragRect.Right - 10, dragRect.Bottom - 10);
- SetRect(NotePallete, 5, 5, 235, 260);{set various rectangles}
- SetRect(EndRect, 345, 235, 370, 250);
- SetRect(StartRect, 345, 195, 370, 210);
- SetRect(TimbreRect, 465, 85, 490, 100);
- SetRect(DurRect, 465, 65, 490, 80);
- SetRect(AmpRect, 465, 45, 490, 60);
- SetRect(FreqRect, 465, 25, 500, 40);
- SetRect(NoteRect, 420, 5, 445, 20);
-
- Dirty := false;
-
- theWatch := GetCursor(watchCursor);
- HLock(Handle(theWatch));
- theSquare := GetCursor(crossCursor);
- HLock(Handle(theSquare));
-
- theErr := SysEnvirons(1, theWorld);
- if (theWorld.machineType >= 0) and (NGetTrapAddress(WNETrapNum, ToolTrap) = NGetTrapAddress(UnImplTrapNum, ToolTrap)) then
- WNE := false
- else
- WNE := true;
- sleep := 10;
- end;
-
- procedure AdjustCursor; {set cursor}
- begin
- if (FrontWindow = MyWindow) and (MyWindow <> nil) then
- begin {our window in front}
- GetMouse(myPt);
- if PtInRect(myPt, NotePallete) then
- SetCursor(theSquare^^) {over note pallete}
- else
- SetCursor(arrow); {over other stuff}
- end
- else
- SetCursor(arrow);
- end;
-
- begin {Start of main body}
- InitMac;
- InitApp;
-
- {finder startup}
- CountAppFiles(message, nDocs);
- if nDocs = 0 then
- begin {no files to open}
- Init_Untitled; {Initialize the window routines}
- Open_Untitled; {Open the window routines at program start}
- end
- else
- begin {files to print or open}
- if message = appPrint then
- begin {print docs}
- for index := 1 to nDocs do
- begin {Loop through docs}
- GetAppFiles(index, theFile);
- if theFile.fType = 'ZZDC' then
- begin {my file}
- VolRefNum := theFile.vRefNum;
- FileName := theFile.fName;
- OpenFile;
- if VolRefNum <> 0 then
- begin
- Open_Untitled;
- SetWTitle(MyWindow, FileName);
- doPrint;
- Close_Untitled(MyWindow);
- end;
- end;
- ClrAppFiles(index);
- end; {Loop through docs}
- doneFlag := true; {quit when done}
- end {print docs}
- else
- begin {open first file, can't open multiple}
- GetAppFiles(1, theFile);
- if theFile.fType = 'ZZDC' then
- begin
- VolRefNum := theFile.vRefNum;
- FileName := theFile.fName;
- OpenFile;
- if VolRefNum = 0 then
- begin
- Init_Untitled; {Initialize the window routines}
- FileName := 'Untitled';
- end;
- Open_Untitled; {Open the window routines at program start}
- SetWTitle(MyWindow, FileName);
- for index := 1 to nDocs do
- ClrAppFiles(index);
- end;
- end;
- end;
-
- repeat {Start of main event loop}
- AdjustMenus;
- AdjustCursor;
-
- if WNE then
- DoIt := WaitNextEvent(everyEvent, myEvent, sleep, nil)
- else
- begin
- SystemTask;
- DoIt := GetNextEvent(everyEvent, myEvent);
- end;
-
- if DoIt then{If event then...}
- begin {Start handling the event}
- code := FindWindow(myEvent.where, whichWindow);{Get which window the event happened in}
-
- case myEvent.what of{Decide type of event}
- MouseDown:{Mouse button pressed}
- begin
- if (code = inMenuBar) then{See if a menu selection}
- begin
- mResult := MenuSelect(myEvent.Where);
- theMenu := HiWord(mResult);{Get the menu list number}
- theItem := LoWord(mResult);{Get the menu list item number}
- Handle_My_Menu(doneFlag, theMenu, theItem);
- end;{End of inMenuBar}
-
- if (code = InDrag) then{See if in a window drag area}
- begin
- DragWindow(whichWindow, myEvent.where, dragRect);{Drag the window}
- end;{End of InDrag}
-
- if (code = inGoAway) then{See if in a window goaway area}
- begin
- if TrackGoAway(whichWindow, myEvent.where) then
- begin
- if dirty then
- begin {need saving}
- GetWTitle(MyWindow, title);
- ParamText(title, '', '', '');
- theValue := D_save_changes;
- if (theValue = I_Yes) then
- begin {wants to save changes}
- if VolRefNum = 0 then
- doSaveAs
- else
- doSave;
- if VolRefNum <> 0 then {did not cancel saving}
- Close_Untitled(MyWindow);
- end
- else if theValue = I_No then
- Close_Untitled(MyWindow);
- end {of needing saved}
- else {no need to save}
- Close_Untitled(MyWindow);
- end;
- end;{End of InGoAway}
-
- if (code = inContent) then{See if in a window}
- begin
- if (whichWindow <> FrontWindow) then
- SelectWindow(whichWindow)
- else
- begin
- SetPort(whichWindow);
- Do_Untitled(myEvent);
- end;
- end;{End of inContent}
-
- if (code = inSysWindow) then{See if a DA selection}
- SystemClick(myEvent, whichWindow);
- end; {End of MouseDown}
-
- KeyDown, AutoKey:{Handle key inputs}
- begin
- with myevent do
- begin
- chCode := BitAnd(message, CharCodeMask);{Get character}
- ch := CHR(chCode);
- if (Odd(modifiers div CmdKey)) then{See if Command key is down}
- begin
- mResult := MenuKey(ch);{See if menu selection}
- theMenu := HiWord(mResult);{Get the menu list number}
- theItem := LoWord(mResult);{Get the menu item number}
- if (theMenu <> 0) then
- Handle_My_Menu(doneFlag, theMenu, theItem);
- end;
- end;
- end; {End for KeyDown,AutoKey}
-
- UpDateEvt:{Update event for a window}
- begin
- whichWindow := WindowPtr(myEvent.message);
- BeginUpdate(whichWindow);
- Update_Untitled(whichWindow);{Update this window}
- EndUpdate(whichWindow);
- end; {End of UpDateEvt}
-
- DiskEvt: {Disk inserted event}
- begin
- if (HiWord(myevent.message) <> noErr) then{See if a diskette mount error}
- begin{due to unformatted diskette inserted}
- myEvent.where.h := ((screenbits.bounds.Right - screenbits.bounds.Left) div 2) - (304 div 2);
- myEvent.where.v := ((screenbits.bounds.Bottom - screenbits.bounds.Top) div 3) - (104 div 2);
- InitCursor;
- chCode := DIBadMount(myEvent.where, myevent.message);{Let the OS handle the diskette}
- end;
- end; {End of DiskEvt}
-
- ActivateEvt:{Window activated event}
- begin
- whichWindow := WindowPtr(myevent.message);
- if odd(myEvent.modifiers) then{Activate, not DeActivate}
- begin{Handle the activate}
- SelectWindow(whichWindow);
- end;
- end; {End of ActivateEvt}
-
- MultiEvt:
- begin
- if Odd(myEvent.message) then
- begin {resume event}
- if FrontWindow = MyWindow then
- begin
- SetPort(MyWindow);
- InvalRect(MyWindow^.portRect);
- end
- else if FrontWindow <> nil then
- begin
- ResumePeek := WindowPeek(FrontWindow);
- if ResumePeek^.windowKind < 0 then
- begin
- myEvent.what := activateEvt;
- BitSet(@myEvent.modifiers, bit0);
- sysResult := SystemEvent(myEvent);
- end;
- end;
- end {of resume event}
-
- else {suspend event}
- begin
- if FrontWindow = MyWindow then
- begin
- SetPort(MyWindow);
- InvalRect(MyWindow^.portRect);
- end
- else if FrontWindow <> nil then
- begin
- ResumePeek := WindowPeek(FrontWindow);
- if ResumePeek^.windowKind < 0 then
- begin
- myEvent.what := activateEvt;
- BitClr(@myEvent.modifiers, bit0);
- sysResult := SystemEvent(myEvent);
- end;
- end;
- end;
- end; {of MultiEvt}
-
- otherwise
- ;
- end; {End of case}
-
- end; {end of GetNextEvent}
- until doneFlag; {End of the event loop}
-
- end. {End of the program}